#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h> // O_xxx的头文件
//自定义宏函数
#define err_exit(MSG) (perror(MSG),exit(1))

int main(int argc,char * args[]){
    int n,from,to; //定义变量
    char buf[1024]; //开辟缓冲区
    if(argc!=3){ //参数检测
        //参数错误提示并退出
        err_exit("Argument error.");
    }
    //源文件打开检测
    if((from = open(args[1],O_RDONLY))<0){
        err_exit("Open file error!");
    }
    //目标文件打开检测
    if((to = open(args[2],O_WRONLY|O_CREAT,0644))<0){
        err_exit("Create file error!");
    }
    //循环读取写入实现复制
    while((n=read(from,buf,sizeof(buf)))>0){
        write(to,buf,n);
    }
    return 0;
}